package business;

import java.util.ArrayList;

import dao.*;
import model.Category;
import model.Product;
import model.User;

public class BusinessAM {
	public BusinessAM() throws Exception{
		userDao = DaoFactory.getUserDao();
		productDao = DaoFactory.getProductDao();
		categoryDao = DaoFactory.getCategoryDao();
	}
	public boolean updateUserInfo(User user) {
		//check whether the user and password is valid
		if(userDao.validateUser(user)){
			userDao.updateUser(user);
			return true;
		}
		return false;
	}
	public boolean updateProductInfo(Product product){
		//check whether the category id is valid.
		
		return false;
	}
	public ArrayList <Category> getAllCategories(){
		ArrayList <Category> categories = categoryDao.getAllCategories();
		return categories;
	}
	public ArrayList <Product> getAllProducts() {
		ArrayList <Product> products = productDao.getAllProducts();
		return products;
	}
	public Product getProductByProductId(String productId) {
		Product product = productDao.getProductById(productId);
		return product;
	}
	public User getUserByUserId(String userId){
		User user = userDao.getUserByUserId(userId);
		return user;
	}
	public boolean validateUser(User user){
		return userDao.validateUser(user);
	}
	public boolean registerUser(User user){
		return userDao.insertUser(user);
	}
	public boolean addProductToDatabase(Product product){
		return productDao.insertProduct(product);
	}
	public boolean addCategoryToDatabase(Category category){
		return categoryDao.insertCategory(category);
	}
	public boolean containsUser(User user){
		return userDao.containsUser(user);
	}
	private CategoryDao categoryDao;
	private ProductDao productDao;
	private UserDao userDao;
}
